package leecode;

public class LeetCode36 {
    public  int maxProfit(int[] prices) {
        int max=0;
        for (int i = 0,j=1; j <prices.length ; j++) {
            while (prices[i]>prices[j]){
                i++;
            }
            if (j <prices.length&&prices[i]<prices[j]){
                max=Math.max(prices[j]-prices[i],max);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        LeetCode36 leetCode36=new LeetCode36();
        int arr[]={1,2,4};
        leetCode36.maxProfit(arr);
    }
}
